import { http } from '@/utils/http/axios';

// 产品API
export function useProductApi() {
  return {
    // 获取产品分页列表
    getProductPage: (params: any) => {
      return http.request({
        url: '/api/Product',
        method: 'GET',
        params,
      });
    },
    
    // 获取产品详情
    getProductDetail: (id: string) => {
      return http.request({
        url: `/api/Product/${id}`,
        method: 'GET',
      });
    },
    
    // 获取所有产品列表
    getAllProducts: (params?: any) => {
      return http.request({
        url: '/api/Product/All',
        method: 'GET',
        params,
      });
    },
    
    // 创建产品
    createProduct: (data: any) => {
      return http.request({
        url: '/api/Product',
        method: 'POST',
        data,
      });
    },
    
    // 更新产品
    updateProduct: (id: string, data: any) => {
      return http.request({
        url: `/api/Product/${id}`,
        method: 'PUT',
        data,
      });
    },
    
    // 删除产品
    deleteProduct: (id: string) => {
      return http.request({
        url: `/api/Product/${id}`,
        method: 'DELETE',
      });
    },
    
    // 启用产品
    enableProduct: (id: string) => {
      return http.request({
        url: `/api/Product/${id}/enable`,
        method: 'PUT',
      });
    },
    
    // 禁用产品
    disableProduct: (id: string) => {
      return http.request({
        url: `/api/Product/${id}/disable`,
        method: 'PUT',
      });
    },
    
    // 上传文件
    uploadFile: (formData: FormData) => {
      return http.request({
        url: '/api/File/Upload',
        method: 'POST',
        headers: {
          'Content-Type': 'multipart/form-data',
        },
        data: formData,
      });
    },
  };
}

// 分类API
export function useCategoryApi() {
  return {
    // 获取分类树
    getCategoryTree: (params?: any) => {
      return http.request({
        url: '/api/Category/Tree',
        method: 'GET',
        params,
      });
    },
    
    // 获取分类列表
    getCategoryList: (params?: any) => {
      return http.request({
        url: '/api/Category',
        method: 'GET',
        params,
      });
    },
    
    // 获取分类详情
    getCategoryDetail: (id: string) => {
      return http.request({
        url: `/api/Category/${id}`,
        method: 'GET',
      });
    },
    
    // 创建分类
    createCategory: (data: any) => {
      return http.request({
        url: '/api/Category',
        method: 'POST',
        data,
      });
    },
    
    // 更新分类
    updateCategory: (id: string, data: any) => {
      return http.request({
        url: `/api/Category/${id}`,
        method: 'PUT',
        data,
      });
    },
    
    // 删除分类
    deleteCategory: (id: string) => {
      return http.request({
        url: `/api/Category/${id}`,
        method: 'DELETE',
      });
    },
    
    // 启用分类
    enableCategory: (id: string) => {
      return http.request({
        url: `/api/Category/${id}/enable`,
        method: 'PUT',
      });
    },
    
    // 禁用分类
    disableCategory: (id: string) => {
      return http.request({
        url: `/api/Category/${id}/disable`,
        method: 'PUT',
      });
    },
  };
} 